package com.tuanzi.loan.business.repository.settlement.impl;

import static com.tuanzi.loan.generated.jooq.loan.Tables.SW_MONEY_FLOW;

import java.util.List;

import org.jooq.impl.TableImpl;
import org.springframework.stereotype.Repository;

import com.tuanzi.loan.business.entity.settlement.SwMoneyFlow;
import com.tuanzi.loan.business.repository.settlement.custom.SwMoneyFlowRepositoryCustom;
import com.tuanzi.loan.core.repository.JOOQBaseRepository;

@Repository
public class SwMoneyFlowRepositoryImpl extends JOOQBaseRepository implements SwMoneyFlowRepositoryCustom {
    @Override
    public List<SwMoneyFlow> getLatestSwMoneyFlowByCompanyId(Long companyId) {
        fields(SW_MONEY_FLOW.fields());
        eq(SW_MONEY_FLOW.COMPANY_ID,companyId);
        return search( record -> {
            SwMoneyFlow swMoneyFlow = new SwMoneyFlow();
            swMoneyFlow.setId(record.get(SW_MONEY_FLOW.ID));
            swMoneyFlow.setMoneyFlowDate(record.get(SW_MONEY_FLOW.MONEY_FLOW_DATE));
            swMoneyFlow.setActualDate(record.get(SW_MONEY_FLOW.ACTUAL_DATE));
            swMoneyFlow.setPingzhengUrl(record.get(SW_MONEY_FLOW.PINGZHENG_URL));
            swMoneyFlow.setMoneyFlowNum(record.get(SW_MONEY_FLOW.MONEY_FLOW_NUM));
            swMoneyFlow.setActualMoney(record.get(SW_MONEY_FLOW.ACTUAL_MONEY));
            swMoneyFlow.setReceiveAccount(record.get(SW_MONEY_FLOW.RECEIVE_ACCOUNT));
            swMoneyFlow.setReceiveAccountName(record.get(SW_MONEY_FLOW.RECEIVE_ACCOUNT_NAME));
            swMoneyFlow.setCompanyId(record.get(SW_MONEY_FLOW.COMPANY_ID));
            return swMoneyFlow;
        });
    }

    @Override
    protected TableImpl getTable() {
        return SW_MONEY_FLOW;
    }
}
